/* 
 * Copyright (c) 2019, CENTRIN.CIYUN.LTD. All rights reserved.
 */
package com.cory.admin.sys.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import com.cory.admin.sys.core.handle.LoginHandle;
import com.cory.admin.sys.core.handle.LoginHandle.DefaultLoginHandle;
import com.cory.admin.sys.core.handle.SystemHandle;
import com.cory.admin.sys.core.handle.SystemHandle.DefaultSystemHandle;
import com.cory.module.msg.admin.AdminMsgService;

/**
 * 配置
 * @author xiongcong
 * @date 2019-02-27
 */
@Configuration
@PropertySource(value = {"classpath:application-admin.properties"})
public class AdminMvcConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/portal/**", "/admin/**");
    }
    
    @Bean
    @ConditionalOnMissingBean(LoginHandle.class)
    public LoginHandle loginHandle() {
        return new DefaultLoginHandle();
    }
    
    @Bean
    @ConditionalOnMissingBean(SystemHandle.class)
    public SystemHandle systemHandle() {
        return new DefaultSystemHandle();
    }
    
    @Bean
    @ConditionalOnMissingBean(AdminMsgService.class)
    public AdminMsgService adminMsgService() {
        return new AdminMsgService();
    }
}
